Data Preprocessing

set.seed(123)
data <- data.frame(
  Order_Date = seq(as.Date("2023-01-01"), as.Date("2023-12-31"), by="day"),
  Category = sample(c("Furniture", "Office Supplies", "Technology"), 365, replace=TRUE),
  Sales = runif(365, 100, 1000),
  Profit = runif(365, -50, 200),
  Region = sample(c("East", "West", "Central", "South"), 365, replace=TRUE),
  Discount = runif(365, 0, 0.3)
)



Task 1: Sales Trend over Time

monthly_sales <- data %>%
  mutate(Month = floor_date(Order_Date, "month")) %>%
  group_by(Month) %>%
  summarise(Total_Sales = sum(Sales))

ggplot(monthly_sales, aes(x=Month, y=Total_Sales)) + 
  geom_line(color="#2c3e50", size=1) +
  geom_point(color="#e74c3c", size=2) +
  labs(title = "Monthly Sales Trend (2023)",
       subtitle = "Total sales growth over the year",
       x="Month", y="Total Sales ($)") +
  theme_minimal() + 
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 16),
    plot.subtitle = element_text(hjust = 0.5, size = 12),
    plot.margin = margin(t = 50)
  )
Figure 1: This chart shows the monthly sales trend for 2023.

Figure 1: This chart shows the monthly sales trend for 2023.



Task 2: Profit by Category

cat_profit <- data %>%
  group_by(Category) %>%
  summarise(Total_Profit = sum(Profit))

ggplot(cat_profit, aes(x=Category, y=Total_Profit, fill= Category)) +
  geom_bar(stat = "identity") +
  scale_fill_brewer(palette="Set2") +
  labs(title="Total Profit by Category",
       x="Product Category", y="Profit ($)") +
  theme_classic() + 
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 16),
    plot.subtitle = element_text(hjust = 0.5, size = 12),
    plot.margin = margin(t = 50)
  )
Figure 1: This chart shows the monthly sales trend for 2023.

Figure 1: This chart shows the monthly sales trend for 2023.



Task 3: Preferred Order Categories

ship_data <- data %>%
  count(Category)

ggplot(ship_data, aes(x=Category, y=n, fill=Category)) +
  geom_col() +
  labs(title="Preferred Categories (Order Count)",
       x="Category", y="Number of Orders") +
  theme_light() + 
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 16),
    plot.subtitle = element_text(hjust = 0.5, size = 12),
    plot.margin = margin(t = 50)
  )
Figure 1: This chart shows the monthly sales trend for 2023.

Figure 1: This chart shows the monthly sales trend for 2023.



Task 4: Discount vs. Profit (Interactive Plot)

p <- ggplot(data, aes(x=Discount, y=Profit, color=Category)) +
  geom_point(alpha=0.6) +
  geom_smooth(method="lm", color="black") + 
  labs(title="Relationship between Discount and Profit",
       x="Discount (0 - 0.3)", y="Profit / Loss ($)") +
  theme_minimal() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold"),
    plot.subtitle = element_text(hjust = 0.5)
  )

ggplotly(p) %>% 
  layout(
    margin = list(t = 100),
    legend = list(
      orientation = "v",
      xanchor = "left",
      yanchor = "middle",     
      x = 1.1,
      y = 0.5,
      bgcolor = "#F8F9F9", 
      bordercolor = "#D5DBDB",
      borderwidth = 1,
      title = list(text = "<b> Category </b>")
      )
    ) %>% 
  htmltools::div(align = "center")



Task 5: Regional Performance

regional_sales <- data %>%
  group_by(Region) %>%
  summarise(Total_Sales = sum(Sales))

ggplot(regional_sales, aes(x=reorder(Region, -Total_Sales), y=Total_Sales, fill=Region)) +
  geom_bar(stat="identity") +
  labs(title="Total Sales by Region",
       x="Region", y="Total Sales ($)") +
  theme_minimal() + 
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold", size = 16),
    plot.subtitle = element_text(hjust = 0.5, size = 12),
    plot.margin = margin(t = 50)
  )
Figure 1: This chart shows the monthly sales trend for 2023.

Figure 1: This chart shows the monthly sales trend for 2023.



Final Conclusion

Based on the comprehensive analysis of the Superstore Sales data, several key insights have been identified that can guide future business strategies:

Sales Performance & Seasonality: The monthly sales trend reveals a clear fluctuation, with significant growth during the latter half of the year. This suggests that holiday seasons and year-end promotions are the primary drivers of revenue.
Actionable Insight: Increasing inventory levels and marketing spend in Q3 and Q4 could further capitalize on this trend.

Profitability by Category: The analysis highlights that the Technology category is the most consistent profit generator, despite having a moderate sales volume compared to others. Office Supplies, while high in transaction count, yield lower margins.
Actionable Insight: The business should focus on cross-selling high-margin Technology products with everyday Office Supplies to maximize overall profit.

The Impact of Discounts on Profit: Our interactive scatter plot confirms a strong inverse relationship between Discounts and Profitability. While discounts are effective for clearing stock, any discount exceeding 20% (0.2) often leads to a direct net loss per transaction.
Actionable Insight: Implement a “Smart Discounting” policy where discounts are capped at 15% unless bundled with high-margin items.

Geographical Insights: Certain regions show high sales but disproportionately low profits. This indicates higher operational costs or aggressive discounting in those specific areas.
Actionable Insight: A deep dive into regional logistics or localized pricing strategies is recommended to stabilize margins across all territories..